#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
using namespace std;

void Adjustdown(vector<int>& v, int n, int parent)
{
	int child = parent * 2 + 1;
	while (child < n)
	{
		if (child + 1 < n && v[child + 1] < v[child])
			++child;
		if (v[child] < v[parent])
		{
			swap(v[child], v[parent]);
			parent = child;
			child = parent * 2 + 1;
		}
		else
			break;
	}
}

void Heapsort(vector<int>& v, int n)
{
	for (int i = (n - 1 - 1) / 2; i >= 0; --i)
	{
		Adjustdown(v, n, i);
	}
	cout << n << ' ';
	for (const auto& e : v)
	{
		cout << e;
		if (e != v[n - 1])
		{
			cout << ' ';
		}
	}
	cout << endl;

	int end = n - 1;
	while (end > 0)
	{
		swap(v[end], v[0]);
		Adjustdown(v, end, 0);
		--end;
		cout << n << ' ';
		for (const auto& e : v)
		{
			cout << e;
			if (e != v[n - 1])
			{
				cout << ' ';
			}
		}
		cout << endl;
	}
}

void test3()
{
	int n;
	while (cin >> n)
	{
		vector<int> v(n, 0);
		for (auto& e : v)
		{
			cin >> e;
		}
		Heapsort(v, n);
	}
	cout << endl;
}

int main()
{
	test3();
	return 0;
}
